package src

import (
	"fmt"
	"os"
	"time"
)

//funcShowTodoList 输出todolist
func (p Todolist) FuncShowTodoList() {
	for id, tododata := range p.toDoList {
		fmt.Printf("%d.%s\t%s\t%s\t%s\n", id, tododata.DoWhat, tododata.StartTime, tododata.EndTime, tododata.DoWhem)
	}
}

//funcShowTodoList 输出todolist
func (p Todolist) FuncShowHaddoList() {
	for id, tododata := range p.hadDoList {
		fmt.Printf("%d.%s\t%s\t%s\t%s\n", id, tododata.DoWhat, tododata.StartTime, tododata.EndTime, tododata.DoWhem)
	}
}

// funcAddanToDo 添加一个ToDo事项
//注意函数是不支持默认参数的,所以这里需要传递每一个参数
func (p *Todolist) FuncAddanToDo(do_what string, start_time string, end_time string) {
	//获取当前时间
	time := time.Now()
	nowTime := fmt.Sprintf("%s月%d号 %d:%d:%d", time.Month(), time.Day(), time.Hour(), time.Minute(), time.Second())

	//添加一个todo信息
	var ToDo todo
	ToDo.DoWhat = do_what
	ToDo.DoWhem = nowTime
	ToDo.StartTime = start_time
	ToDo.EndTime = end_time

	//插入这条信息
	p.toDoList = append(p.toDoList, ToDo)

	p.funcSaveListtoJsonFile()

}

//funcMoveNeedDotoHadDo 已完成某事
func (p *Todolist) FuncMoveNeedDotoHadDo(id int) {

	needMove := p.toDoList[id]
	p.toDoList = append(p.toDoList[:id], p.toDoList[id+1:]...)
	p.hadDoList = append(p.hadDoList, needMove)
	p.funcSaveListtoJsonFile()
}

//funcDelanTodoList 删除一条todolist
func (p *Todolist) FuncDelanTodoList(id int) {
	if len(p.toDoList) <= id {
		fmt.Println("此id不存在")
		os.Exit(1)
	} else {
		p.toDoList = append(p.toDoList[:id], p.toDoList[id+1:]...)
	}
	p.funcSaveListtoJsonFile()
}

//funcDelanHaddoList 删除一条todolist
func (p *Todolist) FuncDelanHaddoList(id int) {
	if len(p.toDoList) <= id {
		fmt.Println("此id不存在")
		os.Exit(1)
	} else {
		p.hadDoList = append(p.hadDoList[:id], p.hadDoList[id+1:]...)
	}
	p.funcSaveListtoJsonFile()
}
